package com.interview.ujiuye1;

import java.util.concurrent.TimeUnit;


public class Demo {
    public static void main(String[] args) throws InterruptedException {
        MyData myData  =new MyData();
        for (int i=0; i< 20; i++){
            new Thread(new Runnable() {
                @Override
                public void run() {
                    for (int j=0; j<1000; j++){
                        myData.addPlusPlus();
                    }
                }
            }).start();
        }
        //等待所有的子线程执行结束
        //Thread.sleep(5000);
        while (Thread.activeCount() > 2){
            Thread.yield();//让步，礼让
        }
        System.out.println("====num===" + myData.num);
    }

    private static void tset() {
        MyData myData  =new MyData();

        new Thread(new Runnable() {
            @Override
            public void run() {

                try { TimeUnit.SECONDS.sleep(3); } catch (InterruptedException e) { e.printStackTrace(); }
                myData.addTo60();//修改成60
                System.out.println(Thread.currentThread().getName()+"==="+myData.num);
            }
        }).start();


        while (myData.num ==0){

        }

        System.out.println("游戏结束......"+myData.num);
    }
}
